package com.example.weight.navigation;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
import com.example.weight.R;
import com.example.weight.greenSeasons.waterDeal.RepairTable;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;

public class GongyixianchangNavigationActivity extends AppCompatActivity {

    private String name, factory;
    private Button gegongxuyongdian,gongyixianchang,duifeidundai,daxiuxianchang;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gongyixianchang_nav);
        Intent previousIntent = getIntent();
        name = previousIntent.getStringExtra("name");
        factory = previousIntent.getStringExtra("factory");
        String permissionLevel = previousIntent.getStringExtra("permissionLevel");

        TitleBar titleBar = findViewById(R.id.titleBar);
        titleBar.setOnTitleBarListener(new OnTitleBarListener() {
            @Override
            public void onLeftClick(View v) {
                finish();
            }

            @Override
            public void onTitleClick(View v) {}

            @Override
            public void onRightClick(View v) {}
        });
        gegongxuyongdian = findViewById(R.id.gegongxuyongdian);
        gongyixianchang = findViewById(R.id.gongyixianchang);
        duifeidundai = findViewById(R.id.duifeidundai);
        daxiuxianchang = findViewById(R.id.daxiuxianchang);
        initNavEnable(permissionLevel);
    }
    public void turnGongyixianchang(View view) {
        Intent intent =new Intent(GongyixianchangNavigationActivity.this, GongyixianchangNeikongNavActivity.class);
        intent.putExtra("name", name);
        intent.putExtra("factory", factory);
        startActivity(intent);
    }
    public void turnGegongxuyongdian(View view) {
        Intent intent =new Intent(GongyixianchangNavigationActivity.this, GongyixianchangGegongxuyongdianNavigationActivity.class);
        intent.putExtra("name", name);
        intent.putExtra("factory", factory);
        startActivity(intent);
    }
    public void turnDaxiuxianchang(View view) {
        Intent intent =new Intent(GongyixianchangNavigationActivity.this, RepairTable.class);
        intent.putExtra("name", name);
        intent.putExtra("factory", factory);
        startActivity(intent);
    }
    public void turnCompostTonBag(View view) {
        Intent intent =new Intent(GongyixianchangNavigationActivity.this, GongyixianchangTonBagNavActivity.class);
        intent.putExtra("name", name);
        intent.putExtra("factory", factory);
        startActivity(intent);
    }
    private void initNavEnable(String permissionLevel) {
        if (permissionLevel.equals("0"))
            return;
        gegongxuyongdian.setEnabled(false);
        gongyixianchang.setEnabled(false);
        duifeidundai.setEnabled(false);
        daxiuxianchang.setEnabled(false);
        if (permissionLevel.contains("各工序用电"))
            gegongxuyongdian.setEnabled(true);
        if (permissionLevel.contains("内控"))
            gongyixianchang.setEnabled(true);
        if (permissionLevel.contains("堆肥吨袋"))
            duifeidundai.setEnabled(true);
        if (permissionLevel.contains("大修现场"))
            daxiuxianchang.setEnabled(true);
    }
}
